//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System.Collections.Generic;
using Mindscape.BackgroundMotion.Model;
using Mindscape.BackgroundMotion.Website.Controllers;
using Mindscape.BackgroundMotion.Website.Controls;
using Mindscape.BackgroundMotion.Website.Infrastructure;
using Mindscape.BackgroundMotion.Website.Views;

namespace Mindscape.BackgroundMotion.Website.MasterPages
{
  [CodeViewer("We used the May 2006 CTP of LINQ to Sql Server to manage data access in BackgroundMotion. A good example of the power of LINQ is the way we can work with the collections of Tags in the system.")]
  [CodeViewerReference(1, @"\Clients\Website\Controllers\ContributionController.cs", 345, 359, "The Tags on this page are loaded from the GetAllTags method on the Contribution controller. We want to only display the Tags which are associated with approved contributions, so to achieve this we first declare 2 re-queryable sets; one of all possible Tags and one of all possible ContributionTags, a join table which links a Contribution to a Tag. Once we have these we express the actual query which will find all the tags where at least one contribution has been approved.")]
  [CodeViewerReference(2, @"\Clients\Website\Controllers\ContributionController.cs", 322, 340, "For the Popular Tags on the left hand navigation, we use the same approach, but with two extra steps. Firstly we load the initial set of tags associated with at least one moderated contribution in to a list which has been ordered in descending order by the number of usages using OrderByDescending(). We then requery that list to only select distinct entries using Distinct() and then take the number of tags we are after using the Take() method.")]
  [CodeViewerReference(3, @"\Clients\Website\Tags.aspx.cs", 30, 36, "Once we have a list of Tags to display we bind them to a TagCloud control which manages the rendering")]
  [CodeViewerReference(4, @"\Clients\Website\Controls\TagCloud.ascx", 13, 19, "When the Tags are bound we use data binding to wire up the Size of the Tag using the Font-Size property")]
  [CodeViewerReference(5, @"\Clients\Website\Controls\TagCloudData.cs", 54, 59, "We determine the size of the Tag by its relative popularity")]  
  public partial class Tags : PageBase<TagsPresenter, ITagsView, IContributionController>, ITagsView
  {
    /// <summary>
    /// A list of tags which will be rendered on this view
    /// </summary>
    public IList<Tag> TagData
    {
      set { TagCloud.TagCloudData = new TagCloudData(value); }
    }
  }
}